package jsyf.oa.dao.returnVisit;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.forms.ComponentsEntity;
import jsyf.oa.entity.returnVisit.ReturnVisitEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by 92852 on 2018/6/27.
 */
@Repository
public class ReturnVisitDao extends BaseDao {
    public ReturnVisitDao() {
        this.iBaseEntity = new ReturnVisitEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, ReturnVisitEntity.class);
    }

    public List<JSONObject> getListInfo(String condition, int requestPage, int pageSize) {
        StringBuffer sql = new StringBuffer();
        sql.append("  SELECT\n" +
                "\tt_sys_company.`NAME` AS companyName,\n" +
                "\tt_sys_depart.`NAME` AS departName,\n" +
                "\tt_sys_role_name.`NAME` AS roleName,\n" +
                "\t(\n" +
                "\t\tCASE\n" +
                "\t\tWHEN (\n" +
                "\t\t\t(\n" +
                "\t\t\t\t`t_sys_role_name`.`FRONT_FLAG` = 1\n" +
                "\t\t\t)\n" +
                "\t\t\tAND (\n" +
                "\t\t\t\t`t_sys_role_name`.`AREA_TYPE` = 0\n" +
                "\t\t\t)\n" +
                "\t\t) THEN\n" +
                "\t\t\t(\n" +
                "\t\t\t\tSELECT\n" +
                "\t\t\t\t\t`t_sys_region`.`NAME`\n" +
                "\t\t\t\tFROM\n" +
                "\t\t\t\t\t`t_sys_region`\n" +
                "\t\t\t\tWHERE\n" +
                "\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t\t`t_sys_region`.`PARENT_ID` <> 0\n" +
                "\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t\tAND `t_sys_region`.`ID` IN (\n" +
                "\t\t\t\t\t\t\tSELECT\n" +
                "\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`REGION_ID`\n" +
                "\t\t\t\t\t\t\tFROM\n" +
                "\t\t\t\t\t\t\t\t`t_sys_user_2_region`\n" +
                "\t\t\t\t\t\t\tWHERE\n" +
                "\t\t\t\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`USER_ID` = `t_sys_user`.`ID`\n" +
                "\t\t\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t)\n" +
                "\t\t\t\tLIMIT 0,\n" +
                "\t\t\t\t1\n" +
                "\t\t\t)\n" +
                "\t\tELSE\n" +
                "\t\t\t(\n" +
                "\t\t\t\tSELECT\n" +
                "\t\t\t\t\t`t_sys_region`.`NAME`\n" +
                "\t\t\t\tFROM\n" +
                "\t\t\t\t\t`t_sys_region`\n" +
                "\t\t\t\tWHERE\n" +
                "\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t\t`t_sys_region`.`PARENT_ID` = 0\n" +
                "\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t\tAND `t_sys_region`.`ID` IN (\n" +
                "\t\t\t\t\t\t\tSELECT\n" +
                "\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`REGION_ID`\n" +
                "\t\t\t\t\t\t\tFROM\n" +
                "\t\t\t\t\t\t\t\t`t_sys_user_2_region`\n" +
                "\t\t\t\t\t\t\tWHERE\n" +
                "\t\t\t\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`USER_ID` = `t_sys_user`.`ID`\n" +
                "\t\t\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t)\n" +
                "\t\t\t\tLIMIT 0,\n" +
                "\t\t\t\t1\n" +
                "\t\t\t)\n" +
                "\t\tEND\n" +
                "\t) AS `regionName`,\n" +
                "\t(\n" +
                "\t\tCASE\n" +
                "\t\tWHEN (\n" +
                "\t\t\t(\n" +
                "\t\t\t\t`t_sys_role_name`.`FRONT_FLAG` = 1\n" +
                "\t\t\t)\n" +
                "\t\t\tAND (\n" +
                "\t\t\t\t`t_sys_role_name`.`AREA_TYPE` = 0\n" +
                "\t\t\t)\n" +
                "\t\t) THEN\n" +
                "\t\t\t(\n" +
                "\t\t\t\tSELECT\n" +
                "\t\t\t\t\t`t_sys_region`.`ID`\n" +
                "\t\t\t\tFROM\n" +
                "\t\t\t\t\t`t_sys_region`\n" +
                "\t\t\t\tWHERE\n" +
                "\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t\t`t_sys_region`.`PARENT_ID` <> 0\n" +
                "\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t\tAND `t_sys_region`.`ID` IN (\n" +
                "\t\t\t\t\t\t\tSELECT\n" +
                "\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`REGION_ID`\n" +
                "\t\t\t\t\t\t\tFROM\n" +
                "\t\t\t\t\t\t\t\t`t_sys_user_2_region`\n" +
                "\t\t\t\t\t\t\tWHERE\n" +
                "\t\t\t\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`USER_ID` = `t_sys_user`.`ID`\n" +
                "\t\t\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t)\n" +
                "\t\t\t\tLIMIT 0,\n" +
                "\t\t\t\t1\n" +
                "\t\t\t)\n" +
                "\t\tELSE\n" +
                "\t\t\t(\n" +
                "\t\t\t\tSELECT\n" +
                "\t\t\t\t\t`t_sys_region`.`ID`\n" +
                "\t\t\t\tFROM\n" +
                "\t\t\t\t\t`t_sys_region`\n" +
                "\t\t\t\tWHERE\n" +
                "\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t\t`t_sys_region`.`PARENT_ID` = 0\n" +
                "\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t\tAND `t_sys_region`.`ID` IN (\n" +
                "\t\t\t\t\t\t\tSELECT\n" +
                "\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`REGION_ID`\n" +
                "\t\t\t\t\t\t\tFROM\n" +
                "\t\t\t\t\t\t\t\t`t_sys_user_2_region`\n" +
                "\t\t\t\t\t\t\tWHERE\n" +
                "\t\t\t\t\t\t\t\t(\n" +
                "\t\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`USER_ID` = `t_sys_user`.`ID`\n" +
                "\t\t\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t\t)\n" +
                "\t\t\t\t\t)\n" +
                "\t\t\t\tLIMIT 0,\n" +
                "\t\t\t\t1\n" +
                "\t\t\t)\n" +
                "\t\tEND\n" +
                "\t) AS `regionId`,\n" +
                "\tt_sys_user.`NAME` AS userName,\n" +
                "\tt_sys_user.`ID` AS userId,\n" +
                "\tt_sys_user.SEX AS sex,\n" +
                "\tt_sys_user.TEL AS tel,\n" +
                "\tt_sys_user.JOB_STATE AS jobState,\n" +
                "\tt_sys_user.ENTRY_DATE AS entryDate,\n" +
                "\tTO_DAYS(NOW()) - TO_DAYS(t_sys_user.ENTRY_DATE) AS entryDays,\n" +
                "\tt_sys_user_parent.`NAME` AS parentName,\n" +
                "\tt_sys_user.PARENT_ID AS parentId,\n" +
                "\tt_sys_return_visit.ID AS id,\n" +
                "\tt_sys_return_visit.CREATE_USER_ID AS createUserId,\n" +
                "\tt_sys_return_visit.CREATE_TIME AS createTime,\n" +
                "\tt_sys_return_visit.RESPONSIBLE_ID AS responsibleId,\n" +
                "\tt_sys_return_visit.RESPONSIBLE_NAME AS responsibleName,\n" +
                "\tt_sys_return_visit.REMARK AS remark,\n" +
                "\tt_sys_return_visit.JOB_TRAINING AS jobTraining,\n" +
                "\tt_sys_return_visit.JOB_TRAINING_STATU AS jobTrainingStatu,\n" +
                "\tt_sys_return_visit.PRODUCT_TRAINING_STATU AS productTrainingStatu,\n" +
                "\tt_sys_return_visit.PRODUCT_TRAINING AS productTraining,\n" +
                "\tt_sys_return_visit.COMPANY_POLICY_STATU AS companyPolicyStatu,\n" +
                "\tt_sys_return_visit.COMPANY_POLICY AS companyPolicy,\n" +
                "\tt_sys_return_visit.BACKSTAGE_MANAGEMENT_STATU AS backstageManagementStatu,\n" +
                "\tt_sys_return_visit.BACKSTAGE_MANAGEMENT AS backstageManagement,\n" +
                "\tt_sys_return_visit.SUPPORT_MATTERS_STATU AS supportMattersStatu,\n" +
                "\tt_sys_return_visit.SUPPORT_MATTERS AS supportMatters,\n" +
                "\tt_sys_return_visit.DIRECT_LEADERSHIP_STATU AS directLeadershipStatu,\n" +
                "\tt_sys_return_visit.DIRECT_LEADERSHIP AS directLeadership,\n" +
                "\tt_sys_return_visit.WORK_ISSUES_STATU AS workIssuesStatu,\n" +
                "\tt_sys_return_visit.GROUP_VISIT_STATU AS groupVisitStatu,\n" +
                "\tt_sys_return_visit.REASON_LEAVING AS reasonLeaving,\n" +
                "\tt_sys_return_visit.COST_SETTLEMENT AS costSettlement,\n" +
                "\tt_sys_return_visit.WORK_HANDOVER AS workHandover,\n" +
                "\tt_sys_return_visit.REMAINING_PROBLEM_STATU AS remainingProblemStatu,\n" +
                "\tt_sys_return_visit.REMAINING_PROBLEM AS remainingProblem,\n" +
                "\tt_sys_return_visit.PROCESSING_PROGRESS AS processingProgress,\n" +
                "\tt_sys_return_visit. STATUS AS status\n" +
                "FROM\n" +
                "\tt_sys_user\n" +
                "LEFT JOIN t_sys_role ON t_sys_role.ID=t_sys_user.ROLE_ID\n" +
                "LEFT JOIN t_sys_depart ON t_sys_depart.ID=t_sys_role.DEPART_ID\n" +
                "LEFT JOIN t_sys_company ON t_sys_company.ID=t_sys_depart.COMPANY_ID\n" +
                "LEFT JOIN t_sys_role_name ON t_sys_role_name.ID = t_sys_role.ROLE_NAME_ID\n" +
                "LEFT JOIN t_sys_user_2_region ON t_sys_user_2_region.USER_ID=t_sys_user.ID\n" +
                "LEFT JOIN t_sys_region ON t_sys_region.ID=t_sys_user_2_region.REGION_ID\n" +
                "LEFT JOIN t_sys_user_leave ON t_sys_user_leave.USER_ID = t_sys_user.ID\n" +
                "LEFT JOIN t_sys_region_2_province ON t_sys_region_2_province.REGION_ID = t_sys_region.ID\n" +
                "LEFT JOIN t_sys_province ON t_sys_province.ID = t_sys_region_2_province.PROVINCE_ID\n" +
                "LEFT JOIN t_sys_return_visit ON t_sys_return_visit.USER_ID = t_sys_user.ID\n" +
                "LEFT JOIN `t_sys_user` `t_sys_user_parent` ON (\n" +
                "\t(\n" +
                "\t\t`t_sys_user`.`PARENT_ID` = `t_sys_user_parent`.`ID`\n" +
                "\t)\n" +
                ")\n" +
                "WHERE\n" +
                "\t1 = 1 "+"\n");
        sql.append(condition);
        sql.append(" GROUP BY\n" +
                "\tt_sys_user.`NAME`,\n" +
                "\tt_sys_user.TEL,\n" +
                "\tt_sys_return_visit.CREATE_USER_ID,\n" +
                "\tt_sys_return_visit.CREATE_TIME,\n" +
                "\tt_sys_return_visit.USER_ID,\n" +
                "\tt_sys_return_visit.RESPONSIBLE_ID,\n" +
                "\tt_sys_return_visit.RESPONSIBLE_NAME,\n" +
                "\tt_sys_return_visit.REMARK,\n" +
                "\tt_sys_return_visit.JOB_TRAINING,\n" +
                "\tt_sys_return_visit.PRODUCT_TRAINING,\n" +
                "\tt_sys_return_visit.COMPANY_POLICY,\n" +
                "\tt_sys_return_visit.BACKSTAGE_MANAGEMENT,\n" +
                "\tt_sys_return_visit.SUPPORT_MATTERS,\n" +
                "\tt_sys_return_visit.DIRECT_LEADERSHIP,\n" +
                "\tt_sys_return_visit.REASON_LEAVING,\n" +
                "\tt_sys_return_visit.COST_SETTLEMENT,\n" +
                "\tt_sys_return_visit.WORK_HANDOVER,\n" +
                "\tt_sys_return_visit.REMAINING_PROBLEM,\n" +
                "\tt_sys_return_visit.PROCESSING_PROGRESS,\n" +
                "\tt_sys_return_visit. STATUS  \n" +
                "ORDER BY entryDays");
        super.appendPageSql(sql, requestPage, pageSize);
        List<JSONObject> records = super.queryForJsonList(sql.toString());
        return records;
    }

    public JSONObject getPersonalByUserId(String condition,String userId) {
        StringBuffer sql = new StringBuffer();
      sql.append("SELECT\n" +
              "t_sys_company.`NAME` AS companyName,\n" +
              "t_sys_depart.`NAME` AS departName,\n" +
              "t_sys_role_name.`NAME` AS roleName,\n" +
              "( CASE\n" +
              "\t\tWHEN (\n" +
              "\t\t\t(\n" +
              "\t\t\t\t`t_sys_role_name`.`FRONT_FLAG` = 1\n" +
              "\t\t\t)\n" +
              "\t\t\tAND (\n" +
              "\t\t\t\t`t_sys_role_name`.`AREA_TYPE` = 0\n" +
              "\t\t\t)\n" +
              "\t\t) THEN\n" +
              "\t\t\t(\n" +
              "\t\t\t\tSELECT\n" +
              "\t\t\t\t\t`t_sys_region`.`NAME`\n" +
              "\t\t\t\tFROM\n" +
              "\t\t\t\t\t`t_sys_region`\n" +
              "\t\t\t\tWHERE\n" +
              "\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t\t`t_sys_region`.`PARENT_ID` <> 0\n" +
              "\t\t\t\t\t\t)\n" +
              "\t\t\t\t\t\tAND `t_sys_region`.`ID` IN (\n" +
              "\t\t\t\t\t\t\tSELECT\n" +
              "\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`REGION_ID`\n" +
              "\t\t\t\t\t\t\tFROM\n" +
              "\t\t\t\t\t\t\t\t`t_sys_user_2_region`\n" +
              "\t\t\t\t\t\t\tWHERE\n" +
              "\t\t\t\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`USER_ID` ="+" '"+userId+"'"+"\n");
      sql.append(")\n" +
              "\t\t\t\t\t\t)\n" +
              "\t\t\t\t\t)\n" +
              "\t\t\t\tLIMIT 0,1\n" +
              "\t\t\t)\n" +
              "\t\tELSE\n" +
              "\t\t\t(\n" +
              "\t\t\t\tSELECT\n" +
              "\t\t\t\t\t`t_sys_region`.`NAME`\n" +
              "\t\t\t\tFROM\n" +
              "\t\t\t\t\t`t_sys_region`\n" +
              "\t\t\t\tWHERE\n" +
              "\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t\t`t_sys_region`.`PARENT_ID` = 0\n" +
              "\t\t\t\t\t\t)\n" +
              "\t\t\t\t\t\tAND `t_sys_region`.`ID` IN (\n" +
              "\t\t\t\t\t\t\tSELECT\n" +
              "\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`REGION_ID`\n" +
              "\t\t\t\t\t\t\tFROM\n" +
              "\t\t\t\t\t\t\t\t`t_sys_user_2_region`\n" +
              "\t\t\t\t\t\t\tWHERE\n" +
              "\t\t\t\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`USER_ID` = "+" '"+userId+"'"+"\n");
      sql.append(")\n" +
              "\t\t\t\t\t\t)\n" +
              "\t\t\t\t\t)\n" +
              "\t\t\t\tLIMIT 0,\n" +
              "\t\t\t\t1\n" +
              "\t\t\t)\n" +
              "\t\tEND\n" +
              "\t) AS `regionName`,\n" +
              "\n" +
              "\n" +
              "(\n" +
              "\t\tCASE\n" +
              "\t\tWHEN (\n" +
              "\t\t\t(\n" +
              "\t\t\t\t`t_sys_role_name`.`FRONT_FLAG` = 1\n" +
              "\t\t\t)\n" +
              "\t\t\tAND (\n" +
              "\t\t\t\t`t_sys_role_name`.`AREA_TYPE` = 0\n" +
              "\t\t\t)\n" +
              "\t\t) THEN\n" +
              "\t\t\t(\n" +
              "\t\t\t\tSELECT\n" +
              "\t\t\t\t\t`t_sys_region`.`ID`\n" +
              "\t\t\t\tFROM\n" +
              "\t\t\t\t\t`t_sys_region`\n" +
              "\t\t\t\tWHERE\n" +
              "\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t\t`t_sys_region`.`PARENT_ID` <> 0\n" +
              "\t\t\t\t\t\t)\n" +
              "\t\t\t\t\t\tAND `t_sys_region`.`ID` IN (\n" +
              "\t\t\t\t\t\t\tSELECT\n" +
              "\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`REGION_ID`\n" +
              "\t\t\t\t\t\t\tFROM\n" +
              "\t\t\t\t\t\t\t\t`t_sys_user_2_region`\n" +
              "\t\t\t\t\t\t\tWHERE\n" +
              "\t\t\t\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`USER_ID` ="+" '"+userId+"'"+"\n");
      sql.append(")\n" +
              "\t\t\t\t\t\t)\n" +
              "\t\t\t\t\t)\n" +
              "\t\t\t\tLIMIT 0,\n" +
              "\t\t\t\t1\n" +
              "\t\t\t)\n" +
              "\t\tELSE\n" +
              "\t\t\t(\n" +
              "\t\t\t\tSELECT\n" +
              "\t\t\t\t\t`t_sys_region`.`ID`\n" +
              "\t\t\t\tFROM\n" +
              "\t\t\t\t\t`t_sys_region`\n" +
              "\t\t\t\tWHERE\n" +
              "\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t\t`t_sys_region`.`PARENT_ID` = 0\n" +
              "\t\t\t\t\t\t)\n" +
              "\t\t\t\t\t\tAND `t_sys_region`.`ID` IN (\n" +
              "\t\t\t\t\t\t\tSELECT\n" +
              "\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`REGION_ID`\n" +
              "\t\t\t\t\t\t\tFROM\n" +
              "\t\t\t\t\t\t\t\t`t_sys_user_2_region`\n" +
              "\t\t\t\t\t\t\tWHERE\n" +
              "\t\t\t\t\t\t\t\t(\n" +
              "\t\t\t\t\t\t\t\t\t`t_sys_user_2_region`.`USER_ID` = "+" '"+userId+"'"+"\n");
      sql.append(")\n" +
              "\t\t\t\t\t\t)\n" +
              "\t\t\t\t\t)\n" +
              "\t\t\t\tLIMIT 0,\n" +
              "\t\t\t\t1\n" +
              "\t\t\t)\n" +
              "\t\tEND\n" +
              "\t) AS `regionId`,\n" +
              "\n" +
              "t_sys_user.`NAME` AS userName,\n" +
              "t_sys_user.`ID` AS userId,\n" +
              "t_sys_user.SEX AS sex,\n" +
              "t_sys_user.TEL AS tel,\n" +
              "t_sys_user.JOB_STATE AS jobState,\n" +
              "t_sys_user.ENTRY_DATE AS entryDate,\n" +
              "TO_DAYS(NOW())-TO_DAYS(t_sys_user.ENTRY_DATE) AS entryDays,\n" +
              "t_sys_user_parent.`NAME` AS parentName,\n" +
              "t_sys_user.PARENT_ID AS parentId,\n" +
              "t_sys_return_visit.ID AS id,\n" +
              "t_sys_return_visit.CREATE_USER_ID AS createUserId,\n" +
              "t_sys_return_visit.CREATE_TIME AS createTime,\n" +
              "t_sys_return_visit.RESPONSIBLE_ID AS responsibleId,\n" +
              "t_sys_return_visit.RESPONSIBLE_NAME AS responsibleName,\n" +
              "t_sys_return_visit.REMARK AS remark,\n" +
              "\n" +
              "\n" +
              "t_sys_return_visit.JOB_TRAINING AS jobTraining,\n" +
              "t_sys_return_visit.JOB_TRAINING_STATU AS jobTrainingStatu,\n" +
              "\n" +
              "t_sys_return_visit.PRODUCT_TRAINING_STATU AS productTrainingStatu,\n" +
              "t_sys_return_visit.PRODUCT_TRAINING AS productTraining,\n" +
              "\n" +
              "t_sys_return_visit.COMPANY_POLICY_STATU AS companyPolicyStatu,\n" +
              "t_sys_return_visit.COMPANY_POLICY AS companyPolicy,\n" +
              "\n" +
              "t_sys_return_visit.BACKSTAGE_MANAGEMENT_STATU AS backstageManagementStatu,\n" +
              "t_sys_return_visit.BACKSTAGE_MANAGEMENT AS backstageManagement,\n" +
              "\n" +
              "t_sys_return_visit.SUPPORT_MATTERS_STATU AS supportMattersStatu,\n" +
              "t_sys_return_visit.SUPPORT_MATTERS AS supportMatters,\n" +
              "\n" +
              "t_sys_return_visit.DIRECT_LEADERSHIP_STATU AS directLeadershipStatu,\n" +
              "t_sys_return_visit.DIRECT_LEADERSHIP AS directLeadership,\n" +
              "\n" +
              "t_sys_return_visit.WORK_ISSUES_STATU AS workIssuesStatu,\n" +
              "t_sys_return_visit.GROUP_VISIT_STATU AS groupVisitStatu,\n" +
              "\n" +
              "t_sys_return_visit.REASON_LEAVING AS reasonLeaving,\n" +
              "t_sys_return_visit.COST_SETTLEMENT AS costSettlement,\n" +
              "t_sys_return_visit.WORK_HANDOVER AS workHandover,\n" +
              "\n" +
              "t_sys_return_visit.REMAINING_PROBLEM_STATU AS remainingProblemStatu,\n" +
              "t_sys_return_visit.REMAINING_PROBLEM AS remainingProblem,\n" +
              "\n" +
              "t_sys_return_visit.PROCESSING_PROGRESS AS processingProgress,\n" +
              "t_sys_return_visit.STATUS AS status\n" +
              "FROM\n" +
              "t_sys_user\n" +
              "LEFT JOIN t_sys_role ON t_sys_role.ID=t_sys_user.ROLE_ID\n" +
              "LEFT JOIN t_sys_depart ON t_sys_depart.ID=t_sys_role.DEPART_ID\n" +
              "LEFT JOIN t_sys_company ON t_sys_company.ID=t_sys_depart.COMPANY_ID\n" +
              "LEFT JOIN t_sys_user_leave ON t_sys_user_leave.USER_ID=t_sys_user.ID\n" +
              "LEFT JOIN t_sys_role_name ON t_sys_role_name.ID=t_sys_role.ROLE_NAME_ID\n" +
              "LEFT JOIN t_sys_return_visit ON t_sys_return_visit.USER_ID=t_sys_user.ID\n" +
              "LEFT JOIN `t_sys_user` `t_sys_user_parent` ON (\n" +
              "\t\t\t\t(\n" +
              "\t\t\t\t\t`t_sys_user`.`PARENT_ID` = `t_sys_user_parent`.`ID`\n" +
              "\t\t\t\t)\n" +
              "\t\t\t)\n" +
              "WHERE 1=1\n");
        sql.append(condition);
        sql.append("GROUP BY\n" +
                "t_sys_user.`NAME`,\n" +
                "t_sys_user.TEL,\n" +
                "t_sys_return_visit.CREATE_USER_ID ,\n" +
                "t_sys_return_visit.CREATE_TIME ,\n" +
                "t_sys_return_visit.USER_ID ,\n" +
                "t_sys_return_visit.RESPONSIBLE_ID ,\n" +
                "t_sys_return_visit.RESPONSIBLE_NAME ,\n" +
                "t_sys_return_visit.REMARK ,\n" +
                "t_sys_return_visit.JOB_TRAINING ,\n" +
                "t_sys_return_visit.PRODUCT_TRAINING ,\n" +
                "t_sys_return_visit.COMPANY_POLICY ,\n" +
                "t_sys_return_visit.BACKSTAGE_MANAGEMENT ,\n" +
                "t_sys_return_visit.SUPPORT_MATTERS ,\n" +
                "t_sys_return_visit.DIRECT_LEADERSHIP ,\n" +
                "t_sys_return_visit.REASON_LEAVING ,\n" +
                "t_sys_return_visit.COST_SETTLEMENT,\n" +
                "t_sys_return_visit.WORK_HANDOVER ,\n" +
                "t_sys_return_visit.REMAINING_PROBLEM ,\n" +
                "t_sys_return_visit.PROCESSING_PROGRESS ,\n" +
                "t_sys_return_visit.STATUS \n");
        JSONObject records = super.queryForJsonObject(sql.toString());
        return records;
    }


}
